/**
 * ==========================
 *        【黯然销魂掌】
 * ==========================
 */
// 技能基本数据
const jsonData = (require('../../json/kungfu/anran-zhang-action.json'))
// pfm - 黯然
const PFMAnran = require('./pfm/anran');
// 公共方法
const SVE = require('../../common/base-tool');
const RSE = require("../../common/base-role");
const COMBAT_D = require("../../common/combat-d");


class anranZhang {
    constructor(me, target) {
        this.me = me;
        this.target = target;
    }

    condition() {
        let me = this.me;
        let target = this.target;

        // 获取技能等级
        let level = '';
        let yunv_level = '';
        if (me.special['anran-zhang']) {
            level = me.special['anran-zhang'];
        }
        if (me.special['yunv-xinjing']) {
            yunv_level = me.special['yunv-xinjing'];
        }

        if ( me.max_neili < 1500) return "你的内力不够。\n";
        if ( me.str < 30 ) return "你没有强劲的膂力无法学黯然消魂掌。\n";
        if ( me.con < 26 ) return "你没有雄厚的体质无法学黯然消魂掌。\n";
        if (yunv_level < (level-30) && level < 230) return "你的玉女心经火候太浅。\n";

        // name = xue_name[random(sizeof(xue_name))];

        // 非男性，伤害降低
        // let tmp = '';
        // if (me.gender != 1) {
        //     tmp = 1 + SVE.random(Math.round(level/20), Math.round(level/5));
        //     tmp = tmp * 0.2;
        // }

        let name = SVE.random(0, jsonData.xue_name.length-1);

        // 获取有效描述
        let actions = []
        for (let i in jsonData.actions) {
            if (level > jsonData.actions[i].lvl) {
                actions.push(jsonData.actions[i]);
            }
        }

        // 普攻：战斗过程
        let i = me.max_qi / me.eff_qi;
        let lvl = me.special['anran-zhang']*2;
        if( i > 3 ) i = 3;
        if( i < 1 ) i = 1;
        let lvl2 = Math.round(lvl/2);
        let lvl3 = Math.round(lvl/3);
        if( i > 1 ){
            me.temp.strength = lvl3;
            me.temp.hurt = 1;
        }
        me.temp.damage = lvl2;
        me.temp.strike = lvl2;
        me.temp.must_be_hit = 1;
        const fighting = COMBAT_D.do_attack(me, target, i, jsonData, level, actions);
        // me.temp.damage -= lvl2;
        // me.temp.strike -= lvl2;

        // j = NewRandom(i, 20, level/5);
        // target = RSE.offensive_target(me);   // 目标

        // 调取 anran pfm
        if(me.temp.anran) {
            let pfm_msg = fighting.msg;
            const anran = new PFMAnran(me, target, jsonData, level).attack();
            switch (anran) {
                case 2:
                    pfm_msg += RSE.message_vision(`<p class="HIY">$N心下万念俱灰，没精打采的挥袖卷出，拍出一掌，只听得噗的一声，这一掌正好击向$n肩头</p>`,me,target);
                    break;
                case 1:
                    pfm_msg += RSE.message_vision(`<p class="HIR">紧跟着$N踢出一脚。这一脚发出时恍恍惚惚，隐隐约约，若有若无。砰的一响，向$n胸口袭去</p>`,me,target);
                    break;
                case 3:
                    pfm_msg += RSE.message_vision(`<p class="HIC">$N心下万念俱灰，没精打采的挥袖卷出，拍出一掌，只听得噗的一声，这一掌正好击向$n肩头</p>`,me,target);
                    break;
                default:
                    pfm_msg += `<p>${anran}</p>`;
                    break;
            }
            log.msg(pfm_msg)
            me.temp.anran = -1;
            return pfm_msg;
            // return ({
            //     "action": msg,
            //     "force" : 250+SVE.random(0,350),
            //     "dodge": SVE.random(30),
            //     "parry": SVE.random(20)+10,
            //     "damage" : 50 + SVE.random(50),
            //     "damage_type" : "瘀伤",
            // });
        }
    }
}

module.exports = anranZhang;